#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "imageprovider.h"
#include "app_environment.h"
#include <QDebug>
#include <QQuickItem>
#include <QQmlComponent>

int main(int argc, char *argv[])
{
    set_qt_environment();
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;

    engine.addImageProvider("icontool", &ImageProvider::instance());
    const QUrl url(u"qrc:/Toys/Main.qml"_qs);
    QObject::connect(
        &engine,
        &QQmlApplicationEngine::objectCreationFailed,
        &app,
        []() { QCoreApplication::exit(-1); },
        Qt::QueuedConnection);
    engine.load(url);

//    auto root = engine.rootObjects().first()->findChild<QQuickItem*>();
//    if(root) {
//        qDebug() << "found:" << root->objectName();
//    }

//    QQmlComponent component = QQmlComponent(&engine, QUrl("qrc:/Toys/Controls/Notification.qml"), root);
//    auto note = component.create();
//    if(note) {
//        qDebug() << "note created";
//    }

//    auto tool = engine.rootObjects().first()->findChild<QObject*>("root_item");
//    if(tool) {
//        qDebug() << "found tool";
//    }

//    for(auto w : engine.rootObjects()) {
//        qDebug() << "name:" << w->objectName();
//    }

    return app.exec();
}
